import 'package:flutter/material.dart';
import 'package:lai_zhan/common/style/AppStyle.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';
import 'package:lai_zhan/widget/BaseScaffold.dart';
import 'package:lai_zhan/common/util/NavigatorUtil.dart';
import 'package:lai_zhan/common/model/shopResult/shop_result.dart';
import 'package:lai_zhan/common/config/Config.dart';
import 'package:lai_zhan/widget/CourseItem.dart';
import 'package:lai_zhan/widget/CoachItem.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:lai_zhan/widget/SubCoachItem.dart';

class ShopPage extends StatefulWidget {
  ShopResult shop;

  ShopPage({this.shop});

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new _ShopPageState(shop);
  }
}

class _ShopPageState extends State<ShopPage> {
  ShopResult shop;

  _ShopPageState(this.shop);

  String url =
      'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1545929952560&di=43869d08b846aa15f1587c120c945f63&imgtype=0&src=http%3A%2F%2Fpic.baike.soso.com%2Fp%2F20120515%2F20120515114505-1317620601.jpg';

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new BaseScaffold(
      title: '门店信息',
      titleColor: Color(AppColors.white),
      backgroundColor: Color(AppColors.primaryColor),
      back: () {
        NavigatorUtil.goBack(context);
      },
      body: new Stack(
        children: <Widget>[
          new FadeInImage.assetNetwork(
            placeholder: Config.DEFALUT_SHOP_IMAGE,
            image: "",
            height: AppSize.AvailableHeight,
            fit: BoxFit.fitHeight,
          ),
          new Positioned(
            child: _renderListView(),
            left: 20,
            bottom: 0,
          )
        ],
      ),
    );
  }

  Widget _renderListView() {
    return new Container(
      width: AppSize.ScreenWidth - 40,
      height: AppSize.AvailableHeight,
      child: new ListView(
        shrinkWrap: true,
        primary: false,
        children: <Widget>[
          _renderEmptyBlock(),
          new Container(
            padding: EdgeInsets.only(left: 5,right: 5),
            decoration: BoxDecoration(
                color: Color(AppColors.translucenceWhite),
                borderRadius: BorderRadius.circular(5.0)),
            width: AppSize.ScreenWidth - 40,
            child: new Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                new Center(
                  child: new Text(
                    '海曙店',
                    style: TextStyle(
                        fontFamily: "font1",
                        fontSize: AppSize.getRealSp(50)),
                  ),
                ),
                new Container(height: 5,),
                new Center(
                  child: Image.asset('lib/images/star5.png',width: AppSize.getRealWidth(130),)
                ),
                new Container(height: 8,),
                new Text('门店信息',style: AppConstant.normalTextBold,),
                new Container(height: 3,),
                _renderOwner(),
                _renderPhone(),
                new Container(height: 1,color: Color(AppColors.grey900),
                margin: EdgeInsets.only(bottom: 10,top: 5),
                ),
                _renderAddress(),
                new Container(height: 1,color: Color(AppColors.grey900),
                  margin: EdgeInsets.only(bottom: 10,top: 5),
                ),
                _renderDescr(),
                new Container(margin: EdgeInsets.only(top: 5,bottom: 5),
                  child: new Text('门店教练',style: AppConstant.normalTextBold,),),
                _renderCoach(),
                new Container(margin: EdgeInsets.only(top: 5,bottom: 5),
                  child: new Text('门店课程',style: AppConstant.normalTextBold,),),
                _renderCourse(),
                new Container(height: 30,)
              ],
            ),
          ),
          _renderEmptyBlock(),
        ],
      ),
    );
  }

  //店长信息
  Widget _renderOwner() {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        new Container(width: 20,),
        new Text(
          '店长  ',
          style: AppConstant.normalTextBold,
        ),
        new Text(
          '张云雷',
          style: AppConstant.normalText,
        )
      ],
    );
  }
  //电话
  Widget _renderPhone() {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        new Container(width: 20,),
        new Text(
          '电话  ',
          style: AppConstant.normalTextBold,
        ),
        new Container(width: AppSize.getRealWidth(190),
          child: new Text(
            '17855833972',
            style: AppConstant.normalText,
          ),
        ),
        new GestureDetector(
          onTap: (){
            _launchURL('17855833972');
          },
          child: new Icon(AppIcon.CALL,size: AppSize.getRealWidth(25),color: Colors.green,),
        )
      ],
    );
  }
  //打电话
  _launchURL(String phone) async {
    String url = "tel:$phone";
    if(await canLaunch(url)) {
      await launch(url);
    }
  }
  //地址及距离
  Widget _renderAddress() {
    return new Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        new Text('地址 ',style: AppConstant.normalTextBold,),
        new Container(width: AppSize.getRealWidth(200),
          child: new Text('海曙区海曙区海曙区海曙区海曙区海曙区',style: AppConstant.normalText,),
        ),
        new Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
          new Container(width: AppSize.getRealWidth(30),
            child: new Icon(AppIcon.DIST,size: AppSize.getRealWidth(20),color: Colors.black,),),
          new Text('100m',style: AppConstant.middleText,)
        ],)
      ],
    );
  }
  //简介
  Widget _renderDescr() {
    return new Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        new Text('简介 ',style: AppConstant.normalTextBold,),
        new Container(width: AppSize.getRealWidth(250),
          child: new Text('即简明扼要的介绍。是当事人全面而简洁地介绍情况的一种书面表达方式，它是应用写作学研究的一种日常应用文体。',style: AppConstant.normalText,),
        )
      ],
    );
  }
  //教练
  _renderCoach() {
    
    List<Widget> widgets = new List();
    for(int i=0;i<4;i++) widgets.add(new SubCoachItem());
    return new GridView.count(crossAxisCount: 2,
    padding: EdgeInsets.only(left: 10,right: 10),
    crossAxisSpacing: 10,
    mainAxisSpacing: 10,
    physics: new NeverScrollableScrollPhysics(),
    shrinkWrap: true,
    children: widgets,
    );
  }
  //课程
  _renderCourse() {
    List<Widget> widgets = new List();
    for(int i=0;i<4;i++) widgets.add(new CourseItem());
    return new Column(
      children: widgets,
    );
  }
  //首尾填充块
  Widget _renderEmptyBlock() {
    return new Container(
      height: 100,
    );
  }
}
